package Service;

import java.util.ArrayList;
import java.util.List;

import dao.UserDao;
import pojo.PageBean;
import pojo.Paper;
import pojo.User;

public class UserService {
	UserDao cdao;
	public int reg(User c) {
		cdao =new UserDao();
		int user=cdao.regUser(c);
		return user;
	}
	public User login(User c) {
		cdao =new UserDao();
		User user=cdao.login(c);
		return user;
}
	public PageBean<User> show(int currentPage,int pageSize) {
		cdao = new UserDao();
		PageBean<User> pb = new PageBean<User>();
		pb.setList(cdao.PageData(currentPage, pageSize));
		pb.setTotal(cdao.getTotal());
		int totalPage=(cdao.getTotal()%pageSize==0)?(cdao.getTotal()/pageSize):(cdao.getTotal()/pageSize+1);
		pb.setTotalPage(totalPage);
		pb.setCurrentPage(currentPage);
		pb.setPageSize(pageSize);
		return pb;
	}
	public List<User> showUserByType(int currentPage,int pageSize,int id){
		cdao = new UserDao();
		List<User>list=new ArrayList<User>();
		list=cdao.showUserByType(currentPage, pageSize, id);
		return list;
	}
	public int update(User p) {
		cdao=new UserDao();
		int flag=cdao.update(p);
		return flag;
	}
	public User getUser(int id) {
		cdao=new UserDao();
		User p =cdao.getOneUser(id);
		return p;
	}
//	public User getoneUser(int id) {
//		cdao=new UserDao();
//		User p =cdao.getOne(id);
//		return p;
//	}
//	public int updatepass(User p) {
//		cdao=new UserDao();
//		int flag=cdao.updatepass(p);
//		return flag;
//	}
}
